package com.xk.Colletcion.List;

import com.xk.Colletcion.pojo.Student;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class listTest {
    public static void main(String[] args) {
        List<Student> studentList = new ArrayList<>();
        Student student1 = new Student("张三", 19, "男", 101, 3);
        Student student2 = new Student("李四", 20, "女", 102, 3);
        Student student3 = new Student("王五", 21, "男", 103, 4);
        studentList.add(student1);
        studentList.add(student2);
        studentList.add(student3);

        //
        System.out.println("原始数据");
        System.out.println("迭代器迭代输出：");
//       Iterator<Student> iterator=studentList.iterator();
//        while (iterator.hasNext()) {
//            Student s=iterator.next();
//            System.out.println(s);
//        }

        for (Iterator<Student> iterator=studentList.iterator();iterator.hasNext();){
            Student s=iterator.next();
            System.out.println(s);
        }
        System.out.println("=================================");
        //
        System.out.println("for-each循环输出：");
        for (Student s : studentList) {
            System.out.println(s.toString());
        }

        System.out.println("\n执行删除操作后的数据");
        studentList.remove(student1);  // 从列表中删除学生1
        System.out.println("迭代器迭代输出：");
        for (Iterator<Student> iterator1 = studentList.iterator(); iterator1.hasNext(); ) {
            Student stu = iterator1.next();
            System.out.println(stu.toString());
        }

        System.out.println("=================================");
        System.out.println("for-each循环输出：");
        for (Student s : studentList) {
            System.out.println(s.toString());
        }

        System.out.println("\n执行修改后的数据");
        studentList.set(0, new Student("赵六", 22, "男", 104, 3));
        System.out.println("迭代器迭代输出：");
        for (Iterator<Student> integer = studentList.iterator(); integer.hasNext(); ) {
            Student stu3 = integer.next();
            System.out.println(stu3.toString());
        }
        System.out.println("=================================");
        System.out.println("for-each循环输出：");
        for (Student s1 : studentList) {
            System.out.println(s1.toString());
            }

        System.out.println("\n查找信息");
        studentList.get(1);
        System.out.println("for循环输出");
        for (int i=0;i<studentList.size();i++){
            System.out.println(studentList.get(1).toString());
            break;
        }


    }
}
